#pragma once
/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * Advanced API 32 API Class Library
 *      Provides static, managed acccess to API calls in the advapi32 library.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
#include "stdafx.h"
#include "BasicSafeHandle.h"

using namespace System;
using namespace System::Text;
using namespace System::IO;
using namespace System::Collections;
using namespace System::Security;
using namespace System::Security::Principal;
using namespace Adaptive::Foundation;
using namespace Adaptive::Win32;

namespace Adaptive
{
	namespace Win32
	{
		/// <summary>
		/// Provides static, managed acccess to API calls in the advapi32 library.
		/// </summary>
		public ref class AdvApi32 sealed
		{
		private:
			/*--------------------------------------------------------------------------------
			 * Constructor / Dispose / Destructor Methods
			 *------------------------------------------------------------------------------*/
			#pragma region Constructor / Dispose / Destructor Methods
			/// <summary>
			/// Initializes a new instance of the class.
			/// </summary>
			/// <remarks>
			/// This constructor is hidden to prevent instantiation.
			/// </remarks>
			AdvApi32();
			#pragma endregion

		public:
			/*--------------------------------------------------------------------------------
			 * Public Static / Shared Methods / Functions
			 *------------------------------------------------------------------------------*/
			#pragma region Public Static / Shared Methods / Functions
			/// <summary>
			/// The <b>AdvAdjustTokenPrivileges</b> function enables or disables privileges in the specified access token. 
			/// Enabling or disabling privileges in an access token requires TOKEN_ADJUST_PRIVILEGES access.
			/// </summary>
			/// <remarks>
			/// 
			/// </remarks>
			/// <param name="tokenHandle">A handle to the access token that contains the privileges to be modified. 
			/// The handle must have TOKEN_ADJUST_PRIVILEGES access to the token. If the PreviousState parameter is not 
			/// NULL, the handle must also have TOKEN_QUERY access.
			/// </param>
			/// <param name="disableAllPrivileges">
			/// Specifies whether the function disables all of the token's privileges. If this value is TRUE, the function 
			/// disables all privileges and ignores the NewState parameter. If it is FALSE, the function modifies 
			/// privileges based on the information pointed to by the <i>newState</i> parameter.
			/// </param>
			/// <param name="newState">
			/// A <see cref="ManagedTokenPrivileges"/> structure that specifies an array of privileges and their 
			/// attributes. If the <b>DisableAllPrivileges</b> parameter is FALSE, the <b>AdjustTokenPrivileges</b> 
			/// function enables, disables, or removes these privileges for the token. The following table describes 
			/// the action taken by the <b>AdjustTokenPrivileges</b> function, based on the privilege attribute.
			/// </param>
			/// <param name="bufferLength">
			/// Specifies the size, in bytes, of the buffer pointed to by the <i>previousState</i> parameter. 
			/// </param>
			/// <param name="previousState">
			/// <see cref="ManagedTokenPrivileges"/> structure to be populated by the function that contains the previous 
			/// state of any privileges that the function modifies
			/// </param>
			/// <param name="returnLength">
			/// The required size, in bytes, of the buffer pointed to by the <i>previousState</i> parameter.
			/// </param>
			/// <returns>
			/// <b>true</b> if the function succeeds; otherwise, <b>false</b>.
			/// </returns>
			static bool AdvAdjustTokenPrivileges(IntPtr tokenHandle, bool disableAllPrivileges, ManagedTokenPrivileges newState, 
											unsigned int bufferLength, ManagedTokenPrivileges previousState, unsigned int returnLength);

			/// <summary>
			/// Allocates a locally unique identifier.
			/// </summary>
			/// <remarks>
			/// The allocated LUID is unique to the local system only, and uniqueness is guaranteed only until the 
			/// system is next restarted.
			/// </remarks>
			/// <returns>
			/// A <see cref="ManagedLuid"/> structure containing the new LUID value.
			/// </returns>
			static ManagedLuid AdvAllocateLocallyUniqueId();
			/// <summary>
			/// Creates a SID for predefined aliases.
			/// </summary>
			/// <param name="sidType">A member of the <see cref="WellKnownSidType"/> enumeration that specifies what the SID 
			/// will identify.
			/// </param>
			/// <returns>
			/// A string containing the new SID value, or <b>null</b> if the function fails.
			/// </returns>
			static String^ AdvCreateWellKnownSid(WellKnownSidType sidType);
			/// <summary>
			/// Creates a SID for predefined aliases.
			/// </summary>
			/// <param name="sidType">A member of the <see cref="WellKnownSidType"/> enumeration that specifies what the SID 
			/// will identify.
			/// </param>
			/// <param name="domainSid">
			/// A <see cref="SecurityIdentifier"/> instance (or <b>null</b>) that identifies the domain control to use when creating the SID.
			/// A <b>null</b> value uses the local computer.
			/// </param>
			/// <returns>
			/// A string containing the new SID value, or <b>null</b> if the function fails.
			/// </returns>
			static String^ AdvCreateWellKnownSid(WellKnownSidType sidType, SecurityIdentifier^ domainSid);
			/// <summary>
			/// Decrypts an encrypted file or directory.
			/// </summary>
			/// <param name="path">The name of the file or directory to be decrypted.</param>
			/// <returns>
			/// If the function succeeds, the return value is <b>true</b>, otherwise, returns <b>false</b>.
			/// </returns>
			/// <exception cref="Win32Exception">Thrown when the function fails and an error code is returned from <b>GetLastError</b>.</exception>
			static bool AdvDecryptFile(String^ path);
			/// <summary>
			/// Encrypts a file or directory. All data streams in a file are encrypted. All new files created in an 
			/// encrypted directory are encrypted.
			/// </summary>
			/// <param name="path">The name of the file or directory to be encrypted.</param>
			/// <returns>
			/// If the function succeeds, the return value is <b>true</b>, otherwise, returns <b>false</b>.
			/// </returns>
			/// <exception cref="Win32Exception">Thrown when the function fails and an error code is returned from <b>GetLastError</b>.</exception>
			static bool AdvEncryptFile(String^ path);
			/// <summary>
			/// Retrieves the name of the user associated with the current thread.
			/// </summary>
			/// <returns>
			/// The user's logon name if successful, otherwise, returns <b>null</b>.
			/// </returns>
			static String^ AdvGetUserName();
		};
	}
};